<template>
   <van-cell class="article-item" @click="$router.push(`/detail/${item.id}`)">
      <template #title>
        <div class="head">
          <img :src="item.avatar" alt="" />
          <div class="con">
            <p class="title van-ellipsis">{{item.stem}}</p>
            <p class="other">{{item.creator}} | {{item.createdAt}}</p>
          </div>
        </div>
      </template>
      <template #label>
        <div class="body van-multi-ellipsis--l2">{{ filterHtmlTag(item.content) }}</div>
        <div class="foot">点赞 {{ item.likeCount }} | 浏览 {{ item.views }}</div>
      </template>
    </van-cell>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      // 对象设置默认值必须以函数的形式返回一个对象, 本质还是在于复用时产生独立的一个对象
      default: () => ({})
    }
  },
  methods: {
    filterHtmlTag (str) {
      // 过滤所有的html标签
      // <HTML> <div> </html> <a> <html> g全局查找 i忽略大小写
      // <html>
      return str.replace(/<[^>]+>/gi, '')
    }
  }
}
</script>

<style lang="less" scoped>
.article-item {
  .head {
    display: flex;
    img {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      overflow: hidden;
    }
    .con {
      flex: 1;
      overflow: hidden;
      padding-left: 10px;
      p {
        margin: 0;
        line-height: 1.5;
        &.title {
          width: 280px;
        }
        &.other {
          font-size: 10px;
          color: #999;
        }
      }
    }
  }
  .body {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    margin-top: 10px;
  }
  .foot {
    font-size: 12px;
    color: #999;
    margin-top: 10px;
  }
}
</style>
